home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Movie Toolbox / Inside Mac Movie Toolbox Code / mtb8.c < prev    next >
Encoding:
Text File  |  1994-12-05  |  2.1 KB  |  81 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            mtb8.c
  3.   Contains:        Video Media Functions
  4.   Written by:    DTS and QT Engineering
  5.   Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  6.   Change History (most recent first):
  7.   <1>         12/4/94    khs        changed the format of the file to the new look and feel
  8.   To Do:
  9. */
  10.  
  11.  
  12. // INCLUDE FILES
  13. #include "mtb.h"
  14.  
  15.  
  16. // FUNCTIONS
  17. void AddVideoSamplesToMedia(Media theMedia,
  18.                             const Rect* trackFrame)
  19. {
  20.     long maxCompressedSize;
  21.     GWorldPtr theGWorld = nil;
  22.     long curSample;
  23.     Handle compressedData = nil;
  24.     Ptr compressedDataPtr;
  25.     ImageDescriptionHandle imageDesc = nil;
  26.     CGrafPtr oldPort;
  27.     GDHandle oldGDeviceH;
  28.     OSErr err = noErr;
  29.  
  30.     err = NewGWorld(&theGWorld, 16,                // pixel depth             
  31.                     trackFrame, nil, nil, (GWorldFlags)0);
  32.     CheckError(err, "\pNewGWorld");
  33.  
  34.     LockPixels(theGWorld->portPixMap);
  35.  
  36.     err = GetMaxCompressionSize(theGWorld->portPixMap, trackFrame, 0,// let ICM choose depth
  37.                                 codecNormalQuality, 'rle ', (CompressorComponent)anyCodec, &maxCompressedSize);
  38.     CheckError(err, "\pGetMaxCompressionSize");
  39.  
  40.     compressedData = NewHandle(maxCompressedSize);
  41.     CheckError(MemError(), "\pNewHandle");
  42.  
  43.     MoveHHi(compressedData);
  44.     HLock(compressedData);
  45.     compressedDataPtr = StripAddress(*compressedData);
  46.  
  47.     imageDesc = (ImageDescriptionHandle)NewHandle(4);
  48.     CheckError(MemError(), "\pNewHandle");
  49.  
  50.     GetGWorld(&oldPort, &oldGDeviceH);
  51.     SetGWorld(theGWorld, nil);
  52.  
  53.     //••••••• changed to <= 30
  54.     for (curSample = 1; curSample <= 30; curSample++)
  55.     {
  56.         EraseRect(trackFrame);
  57.         DrawFrame(trackFrame, curSample);
  58.  
  59.         err = CompressImage(theGWorld->portPixMap, trackFrame, codecNormalQuality, 'rle ', imageDesc, compressedDataPtr);
  60.         CheckError(err, "\pCompressImage");
  61.  
  62.         err = AddMediaSample(theMedia, compressedData, 0,// no offset in data
  63.                              (**imageDesc).dataSize, 60,// frame duration = 1/10 sec
  64.                              (SampleDescriptionHandle)imageDesc, 1,// one sample
  65.                              0,                    // self-contained samples
  66.                              nil);
  67.         CheckError(err, "\pAddMediaSample");
  68.     }
  69.  
  70.     SetGWorld(oldPort, oldGDeviceH);
  71.  
  72.     if (imageDesc)
  73.         DisposeHandle((Handle)imageDesc);
  74.     if (compressedData)
  75.         DisposeHandle(compressedData);
  76.     if (theGWorld)
  77.         DisposeGWorld(theGWorld);
  78. }
  79.  
  80.  
  81.